import { useState, useEffect } from 'react'
import { getCurrentTime } from '../../lib'

export default function Page(props:any) {

  return (
    <main>
      <h1>Posts List Page</h1>
      <h4>{props.dt}</h4>
      <ul>
      { props.data?.map((item:any, index:number) => (
        <li key={index}>
          <h4>{item.title}</h4>
        </li>
      ))
      }
      </ul>
    </main>
  )
}

export async function getStaticProps () {
  const dt = getCurrentTime()
  const response = await fetch('https://dummyjson.com/posts')
  const reply = await response.json()

  return ({
    props: {
      dt,
      data: reply.posts
    }
  })
}